#! /usr/bin/env  python

from DrupalSoap_services import *
import sys

filename ="VBLMetaMan.wsdl" 
FILENAME = "https://vbl.synchrotron.org.au/MetaMan/VBLMetaMan.wsdl"
URL =  "http://cima.chem.usyd.edu.au:8080/?q=services/soap"
LOGNAME="admin"
PASSWORD="CSAFPropPass"


if __name__ == '__main__':
    print "locating the service"
    loc = DrupalSoapLocator()

    # prints messages sent and received if tracefile is set
    import sys
    kw = {     'tracefile' : sys.stdout, 
        'user': LOGNAME, 'password':PASSWORD,
        'url': URL,
        'auth' : ( ZSI.client.AUTH.httpbasic,  LOGNAME, PASSWORD ) }

    print "binding ..."
    binding = loc.getDrupalSoapPortType(**kw) # returns SOAP object

    print "\ntry to login ..."
    request = user_loginRequest()
    request._username = LOGNAME
    request._password = PASSWORD
    response = binding.user_login(request)
    resp = response._return
    print "got resp: " , type(resp)
    print "got response: " , resp


    print "\nget scientists ..."
    import datetime
    date = list(datetime.datetime.now().timetuple())
    date[6]=0
    print date
    date = [2009, 11, 26, 15, 41, 3, 0, 330, -1]
    request = proposaldb_getAllScientistsSinceRequest()
    request._date=date
#    request._date=[2010, 11, 26, 15, 41, 3, 0, 330, -1]
    response = binding.proposaldb_getAllScientistsSince(request)
    print "did we get anything? "
    resp = response._return
    print "got resp: " , type(resp)
    print "got resp: " , resp

    print "\nget log Id..."
    request = proposaldb_xgetLogIdFromDataset()
    request._dataset_name="mm03"
    response = binding.proposaldb_xgetLogIdFromDataset(request)
    print "did we get anything? "
    resp = response._return
    print "got resp: " , type(resp)
    print "got resp: " , resp

    import sys
    sys.exit()

    print "\ntry to connect ..."
    request = system_connectRequest()
    response = binding.system_connect(request)
    print "did we connect? "
    resp = response._return
    print "got resp: " , type(resp)
    print "got resp: " , resp

   
    print "\nget scientists ..."
    request = proposaldb_getAllScientistsSinceRequest()
    import datetime
    date = list(datetime.datetime.now().timetuple())
    date[6]=0
    date = [2004, 1, 1, 0, 0, 0, 0, 330, -1]
    request._date=date
#    request._date=[1, 11, 26, 15, 41, 3, 0, 330, -1]
    print date
    response = binding.proposaldb_getAllScientistsSince(request)
    print "did we get anything? "
    resp = response._return
    print "got resp: " , type(resp)
    print "got resp: " , resp

    print "\ntry to logout ..."
    request = user_logoutRequest()
    #request._username = LOGNAME
    #request._password = PASSWORD
    response = binding.user_logout(request)
    resp = response._return
    print "got resp: " , type(resp)
    print "got response: " , resp

    print "\ngetting Prop Echo ..."
    request = proposaldb_echoRequest()
    request._message = "The bloody thing worked"
    response = binding.proposaldb_echo(request)
    resp = response._return
    print "got resp: " , type(resp)
    print "got result: " , resp
